﻿/*##########  Minus & Plus @ Portal ###################*/

function resizeToc(){
	var width = $("#toc").width();
	if(width == 250)
	{
		document.getElementById("toc").style.width = "10px";
	}
	else
	{
		document.getElementById("toc").style.width = "250px";
	}
}

function GetMostReadMore() {

    var ele = document.getElementById("contentDivImg");
    var imageEle = document.getElementById("imageDivLink");
    if (ele.style.display == "block") {
        ele.style.display = "none";
        $("#imgGetMostReadMore").attr('src', '/Views/Shared/homepage/images/plus.png');

    }
    else {
        ele.style.display = "block";
        $("#imgGetMostReadMore").attr('src', '/Views/Shared/homepage/images/minus.png');

    }
}


function GetMostCommentedMore() {

    var ele = document.getElementById("contentDivCommentImg");
    var imageEle = document.getElementById("imageDivCommentLink");


    if (ele.style.display == "block") {
        ele.style.display = "none";
        $("#imgGetMostCommentedMore").attr('src', '/Views/Services/MostSentArticle/images/plus.png');

    }
    else {
        ele.style.display = "block";
        $("#imgGetMostCommentedMore").attr('src', '/Views/Shared/homepage/images/minus.png');

    }
}

function GetMostSentMore() {

    var ele = document.getElementById("contentDivSentImg");
    var imageEle = document.getElementById("imageDivSentLink");


    if (ele.style.display == "block") {
        ele.style.display = "none";
        $("#imgGetMostSentMore").attr('src', '/Views/Services/MostSentArticle/images/plus.png');

    }
    else {
        ele.style.display = "block";
        $("#imgGetMostSentMore").attr('src', '/Views/Shared/homepage/images/minus.png');

    }
}





function ShowMostArticles() {

    if (document.getElementById("contentDivImg")) {
        $("#contentDivImg").hide();
    }

    if (document.getElementById("contentDivCommentImg")) {
        $("#contentDivCommentImg").hide();
    }
    if (document.getElementById("contentDivSentImg")) {
        $("#contentDivSentImg").hide();
    }
    if (document.getElementById("imageDivCommentLink")) {
        $("#imgGetMostCommentedMore").attr('src', '/Views/Services/MostSentArticle/images/plus.png');
        ///document.getElementById("imageDivCommentLink").innerHTML = '<img src="/Views/Services/MostSentArticle/images/plus.png">';
    }

    if (document.getElementById("imageDivSentLink")) {
        $("#imgGetMostSentMore").attr('src', '/Views/Services/MostSentArticle/images/plus.png');
        //   document.getElementById("imageDivSentLink").innerHTML = '<img src="/Views/Services/MostSentArticle/images/plus.png">';
    }

    if (document.getElementById("imageDivLink")) {
        $("#imgGetMostReadMore").attr('src', '/Views/Services/MostSentArticle/images/plus.png');
        //document.getElementById("imageDivLink").innerHTML = '<img src="/Views/Services/MostSentArticle/images/plus.png">';
    }





}

/*########## End Minus & Plus @ Portal ###################*/



/*Check If IE Detected...*/
function isIe() {
    if ($.browser.msie) {
        return $.browser.msie;
    } else {
        return false;
    }
}

/*Check if IE7 Detected...*/
function isIe7() {
    if ($.browser.msie && $.browser.version == '7.0') {
        return true;
    } else {
        return false;
    }
}

/*Check if IE8 Detected...*/
function isIe8() {
    if ($.browser.msie && $.browser.version == '8.0') {
        return true;
    } else {
        return false;
    }
}

/*Check if IE9 Detected...*/
function isIe9() {
    if ($.browser.msie && $.browser.version == '9.0') {
        return true;
    } else {
        return false;
    }
}

function isChrome() {
    return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
}

function isSafari() {
    return navigator.userAgent.toLowerCase().indexOf('safari/') > -1 && !isChrome();
}

function isOpera() {
    return navigator.userAgent.toLowerCase().indexOf('opera') > -1;
}

var autoSlides = 0, photoAlbumTimer = '', photoAlbumHooverStatus = false, indexClickedPager = 0;
function photoAlbumAutoSlider(autoSlidesParam, pagers) {
    autoSlides = autoSlidesParam;

    photoAlbumTimer = window.setInterval(function () {
        if (!photoAlbumHooverStatus) {
            if (autoSlides > pagers) {
                pASlider_ClearInterval();
                photoAlbumAutoSlider(0, pagers);
            } else {
                $('#photosPagerContainer a.pager-' + autoSlides++).trigger('click');
            }
        }
    }, 4000);
}

function pASlider_ClearInterval() {
    window.clearInterval(photoAlbumTimer);
}
/*********arabic market ticker**************/

var latNewsArrowPos = new Array(245, 148, 39), stopFlag = false, arrowPos = '';
/*var latNewsArrowPos = new Array(266, 172, 69), stopFlag = false, arrowPos = '';*/
function moveLatestNewsArrow(thmbIndex, selRowIndex) {
    arrowImgPos = parseInt(latNewsArrowPos[thmbIndex]) + 'px';
    $('.latestNewsContent:eq(' + selRowIndex + ') .arrowRail .arrowImage').stop(1, 0).animate({
        left: arrowImgPos
    }, 700, 'easeOutCirc', function () {
        arrowImgPos = '';
    });
}

/*********** get تقارير المراسلين ***********/

function RenderLatest24hReports() {
    var __url = '/ks3services/GetfromchannelsiteJson/1/8/rp';

    $.getJSON(__url, null, function (json) {

        ReportsJObj = jQuery.parseJSON(json);
        var index = 0;
        var SectionHTML = "";
        var _rptTitle = "";
        if (ReportsJObj[0] != null) {
            while (ReportsJObj[index] != null && index < 8) {

                vidId = ReportsJObj[index].BCGuid;

                _rptTitle = ReportsJObj[index].ArMainTitle;
               // _rptTitle = _rptTitle.replace(/\"/g, "\\\"");
                SectionHTML = SectionHTML + '<li class="reportsThumbItem">' +
                        '<div class="reportsThumbnail">' +
                            '<a href="/reportslibrary/pages?id=' + ReportsJObj[index].ObjectId + '">' +
                                '<img src="/file/getimagecustom/' + ReportsJObj[index].Image686X515 + '/151/113" width="151" height="113" /><span class="playIcon"></span><!--playIcon--></a></div>' +
                        '<div class="reportsTitle" id="reportsTitle_' + index + '">' +
                            '<a href="/reportslibrary/pages?id=' + ReportsJObj[index].ObjectId + '">' + _rptTitle + '</a></div>' +
                        '<div class="reportsBrief" id="reportsBrief_' + index + '"></div>' +
                    '</li>';
                index++;
            }
            if (index > 0) {
                $('#reporterReportsContainer').removeClass('hide');

            }
            $('.reportsThumbnailsList').html(SectionHTML);
            index = 0;
            while (ReportsJObj[index] != null && index < 8) {
                _rptTitle = ReportsJObj[index].ArMainTitle;
                _rptTitle = _rptTitle.replace(/\"/g, "\\\"");
                cropText(_rptTitle, ReportsJObj[index].Arsummary, 8, $('#reportsTitle_' + index), $('#reportsBrief_' + index), 18, 18);
                index++;
            }
            $('#reporterReports').removeClass('loading');
        }

        var maxReportsHeight = 0, reportInstance = '';

        //        $('.reportsThumbnailsList .reportsThumbItem').each(function () {
        //            reportInstance = parseInt($(this).height());
        //            if (reportInstance > maxReportsHeight) {
        //                maxReportsHeight = reportInstance;
        //            }
        //        });

        /*Reporter Reports Block*/
        var jcarousileObject = {
            mouseWheel: false,
            auto: false,
            speed: 500,
            easing: 'easeInQuint',
            circular: false,
            visible: 4,
            start: $('.reporterReports .carousileBar ul li').length - 4,
            scroll: 4,
            btnNext: "#Carousile_Prev_Button",
            btnPrev: "#Carousile_next_Button",
            beforeStart: function () { },
            afterEnd: function (a) { }
        };
        $('.reporterReports .carousileBar').jCarouselLite(jcarousileObject);
        $('.reportsThumbnailsList .reportsThumbItem').height('262px');
        //$('.reportsThumbnailsList .reportsThumbItem').height(maxReportsHeight);
    });
}

/********* end get تقارير المراسلين **********/

/*********** Genenral Crop Text ******************/
function cropText(title, summary, totalLine, titleDiv, summaryDiv, titleLineH, summaryLineH) {
    try {
        var titleHeight;
        var titleLines;
        var sum = '';
        var lines = 0;
        var divHeight;
        titleHeight = $(titleDiv).height();
        titleLines = titleHeight / titleLineH;

        totalLine = totalLine - titleLines;

        /******************/
        var desDiv = $(summaryDiv)

        $(desDiv).html(summary);
        divHeight = $(desDiv).height();
        lines = divHeight / summaryLineH;
        if (lines > totalLine) {
            lines = 0;
            $(desDiv).html('');
            $.each(summary.split(' '), function (index, value) {
                if (lines <= totalLine) {
                    $(desDiv).html($(desDiv).html() + value + " " + "...");
                    divHeight = $(desDiv).height();
                    lines = divHeight / summaryLineH;
                    $(desDiv).html($(desDiv).html().substring(0, $(desDiv).html().lastIndexOf(' ') + 1));
                }
            });
            /***********  to remove last space then last word  ***/
            $(desDiv).html($(desDiv).html().substring(0, $(desDiv).html().lastIndexOf(' ')));
            $(desDiv).html($(desDiv).html().substring(0, $(desDiv).html().lastIndexOf(' ')));
            /***************************/
            $(desDiv).html($(desDiv).html() + "...");
        }
        else {
            $(desDiv).html(summary);
        }
    }
    catch (Err) {
        $(summaryDiv).html(summary);
    }
}

/********* end crop text function ****************/


/********* Breaking News *********/
/********* Breaking News *********/
function GetBreakingNewsServicePortalEdition(layout) {

    $("#BreakingNewsAJAXRespons").html('');
    loadUrl = "/Services/BreakingNews/" + layout;
    $("#BreakingNewsAJAXRespons").load(loadUrl, function (response, status) {
        if (status == "success") {
            // debugger;
            if ($.trim(response) != "") {
                $("#BreakingNewsAJAXRespons").show();
            }
            //  $("#error").html(msg + xhr.status + " " + xhr.statusText);
        }
    });


}

/********** End Breaking News *********/


/********** Search Box  *************/

function BuildSimpleSearch() {
    var SearchResultURL;
    var searchtext = $('#txtSearch').val();

    SearchResultURL = "/home/search?q=" + searchtext + "&client=default_frontend&proxystylesheet=portalsite&output=xml_no_dtd&filter=p&lr=lang_ar&requiredfields=searchablePC:searchablePC";
    document.location.href = SearchResultURL;
}

function parametersChecking(Str, SpecialCheck) {
    // Seperate Between Chars With ##
    var SpecialCharsCheck = new Array()
    var SpecialCharsCheck = SpecialCheck.split('##')
    var Invalid
    var InvalidChars
    Invalid = false;
    InvalidChars = ''
    try {
        if (Str != '') {
            for (var I = 0; I < SpecialCharsCheck.length; I++) {
                if (SpecialCharsCheck[I] != '') {
                    if (Str.indexOf(SpecialCharsCheck[I]) != -1) {
                        Invalid = true
                        InvalidChars = InvalidChars + ' ' + SpecialCharsCheck[I]
                    }
                }
            }
            if (Str.indexOf("'") != -1) {
                Invalid = true
                InvalidChars = InvalidChars + ' ' + "'"
                if ($('#txtSearch')) {
                    $('#txtSearch').focus();
                }
            }
        }
        if (Invalid) {
            if ($('#txtSearch')) {
                $('#txtSearch').focus();
            }
            return InvalidChars
        }
        else {
            return null
        }
    }
    catch (Err) {
        return InvalidChars
    }

}

/********** Search Box  *************/
/***** SubHeader Menu *****/
function ShowSubHeaderMenu(index) {
    $("#subMenuContainer").html($("#subMenuContainer" + index).html());
    $(".mainMenuItem").each(function () {
        $(this).removeClass('activeItem');
    });
    $("#mainMenuListItem" + index).addClass('activeItem');

    /*To fix More links in submenu*/
    /*Other Sites Drop Down*/
    var dDHoverStat = false;
    $('.dropDownMenuList2').hover(function () {
        dDHoverStat = true;
        if (dDHoverStat) {
            $(this).addClass('openedDropDownMenu2');
            $('.otherSitesItem2 ul, .dropDownMenuList2 li ul').fadeIn(50);
            if ($(this).hasClass('.activeItem')) {
                $('.dropDownItem2 ul').css('display', 'none');
            }
        }
    }, function () {
        dDHoverStat = false;
        if (!dDHoverStat) {
            $('.otherSitesItem2 ul').fadeOut(50);
            $('.dropDownMenuList2').removeClass('openedDropDownMenu2');
        }
    });

    $('.dropDownMenuList2 ul li').hover(function () {
        $(this).addClass('shadedItem2');
    }, function () {
        $(this).removeClass('shadedItem2');
    });

}
/***** SubHeader Menu *****/

/*leftSide News Block timer...*/
//var indexOfActiveNewsThum = 0, lNewsPausedShow = false, latestNewsTimer = '';
//latestNewsTimer = window.setInterval(function () {
//    if (!lNewsPausedShow) {
//        $('.latestNewsItem .latestNewsThumb:eq(' + indexOfActiveNewsThum + ') a:not(.activeThumb)').trigger('click');
//        indexOfActiveNewsThum++;
//        if (indexOfActiveNewsThum > 8) {
//            indexOfActiveNewsThum = 0;
//        }
//    }
//}, 5000);

function setPhotoAlbumTitle(titleText) {
    //    var NewText = '';

    //    var words = titleText.split(/\W+/);
    //    if (titleText.length > 40) {
    //        for (var i = 0; i < words.length; i++) {
    //            var lengthWord = words[i].length;
    //            var totalLength = NewText.length + lengthWord
    //            if (totalLength > 40) {
    //                break;
    //            }
    //            else {
    //                NewText += words[i] + " ";
    //            }
    //        }
    //        NewText += "...";

    //        $('.photoAlbum_block .photoTitle .photoText').text(NewText);
    //    }
    //    else {
    $('.photoAlbum_block .photoTitle .photoText').html(titleText);
    //}
}

/***********reuters popups***********************/

function getReuterspopup() {
    $.get('/ReutersDashboard/ebusinessDashboard/MarketsPopupArabic', '', function (result, status, respones) {

        if (status == 'success') {

            $('body').prepend($('#popupcontent').html(result));
            $("#popupcontent").show();
        }
    });
}

/*********** end reuters popups*********/

function DrawPopup(obj) {
    var mediaType = $(obj).attr('mediaType');
    $('#hdnplayerType').attr('value', mediaType);
    var ResID = $(obj).attr('id');
    var ResExt = $(obj).attr('extension');
    if ($('#hdnplayerType').attr('value') == 'Audio') {
        $('iframe#ifGetVideoPlayer').attr('src', '/audioplayer/' + ResID + "?extension=" + ResExt + "&");
    }
    else {
        $('iframe#ifGetVideoPlayer').attr('src', '/videoplayer/' + ResID + "?extension=" + ResExt + "&opener=" + window.location.pathname);
    }
    $('.basic-modal-content').modal();
    $('.simplemodal-wrap').css('overflow', 'hidden');
    $('.simplemodal-wrap').css('width', '620px');
    $('.simplemodal-wrap').css('height', '700px');

    return false;

}

$(document).ready(function () {
    /*Membership  Login Form Drop down fix*/
    $('.topHeaderLinksItem.MembershipShowBtn').live('click', function () {
        $('.dropDownMenuList').addClass('superHide');
    });

    $('.MembershipHideBtn').live('click', function () {
        $('.dropDownMenuList').removeClass('superHide');
    });

    /*Other Sites Drop Down*/
    var dDHoverStat = false;
    $('.dropDownMenuList').hover(function () {
        dDHoverStat = true;
        if (dDHoverStat) {
            $(this).addClass('openedDropDownMenu');
            $('.otherSitesItem ul, .dropDownMenuList li ul').fadeIn(50);
        }
    }, function () {
        dDHoverStat = false;
        if (!dDHoverStat) {
            $('.otherSitesItem ul').fadeOut(100);
            $('.dropDownMenuList').removeClass('openedDropDownMenu');
        }
    });

    $('.dropDownMenuList ul li').hover(function () {
        $(this).addClass('shadedItem');
    }, function () {
        $(this).removeClass('shadedItem');
    });







    /*Country Drop Down*/
    var dDHoverStatcountry = false;
    $('.dropDownMenuListcountry').hover(function () {
        dDHoverStat = true;
        if (dDHoverStat) {
            $(this).addClass('openedDropDownMenu');
            $('.otherSitesItemcountry ul, .dropDownMenuListcountry li ul').fadeIn(50);
        }
    }, function () {
        dDHoverStatcountry = false;
        if (!dDHoverStatcountry) {
            $('.otherSitesItemcountry ul').fadeOut(100);
            $('.dropDownMenuListcountry').removeClass('openedDropDownMenu');
        }
    });

    $('.dropDownMenuListcountry ul li').hover(function () {
        $(this).addClass('shadedItem');
    }, function () {
        $(this).removeClass('shadedItem');
    });







    /*Breacking news*/
    GetBreakingNewsServicePortalEdition('portal');

    /*********** get تقارير المراسلين ***********/
    RenderLatest24hReports();
    /********* end get تقارير المراسلين **********/

    /*Press Freedom Block Navigation*/
    //    var imgPath = '', selectedTitle = '', selectedBrief = '', selectedLink = '';
    //    $('.freedomsItem').live('click', function () {
    //        imgPath = $('.press-img img', this).attr('rel');
    //        selectedTitle = $('.press-title a', this).html();
    //        selectedBrief = $('.press-brief', this).text();
    //        selectedLink = $('.press-img img', this).attr('lnk');
    //        $('.field1-image img').attr('src', imgPath);
    //        $('.field1-image a').attr('href', selectedLink);
    //        $('.field1-material .material-title').html('<a href="' + selectedLink + '">' + selectedTitle + '</a>');
    //        $('.field1-material #material-text').text(selectedBrief);
    //        $('.freedomsItem').removeClass('activeFreedomItem');
    //        $(this).addClass('activeFreedomItem');
    //    });

    /*Portal Main Newsticker...*/
    /*Invoke Newsticker plugin...*/
    $('#js-news').ticker({ speed: 0.12, ajaxFeed: false, feedUrl: false, feedType: 'xml', htmlFeed: true, debugMode: false, controls: true, titleText: 'آخر التطورات:', displayType: 'reveal', direction: 'rtl', pauseOnItems: 2000, fadeInSpeed: 800, fadeOutSpeed: 400 });

    /*Re-arrange the controls items...*/
    var tickerControls = $('.portalNewsTicker .ticker-controls').clone(true);
    $('.portalNewsTicker .tickerControls').html(tickerControls);
    var pauseButton = $('.portalNewsTicker .tickerControls .jnt-play-pause').clone(true);
    $('.portalNewsTicker .tickerControls .jnt-play-pause').remove();
    $('.portalNewsTicker .tickerControls li.jnt-prev').after(pauseButton);
    $('.portalNewsTicker .ticker-wrapper .ticker-controls').remove();

    /*side block tabs navigation...*/
    var tabDivName = '';
    $('.sideBlock .tabsContainer .tabsList .tabItem a').live('click', function () {
        if (!$(this).parents('.tabItem').hasClass('activeItem')) {
            /*Tabs Navigation...*/
            $('.tabItem', $(this).parents('.tabsList')).removeClass('activeItem');
            $(this).parent('.tabItem').addClass('activeItem');

            /*Showing\hiding Tab Containers...*/
            tabDivName = $(this).attr('rel');
            $('.tabsContainersWrapper .tabsContainers', $(this).parents('.sideBlock')).removeClass('shownDiv');
            $('.tabsContainersWrapper .tabsContainers', $(this).parents('.sideBlock')).hide();
            $('.tabsContainersWrapper ' + tabDivName, $(this).parents('.sideBlock')).addClass('shownDiv');
            $('.tabsContainersWrapper .tabsContainers', $(this).parents('.sideBlock')).stop(1, 0);
            $('.tabsContainersWrapper ' + tabDivName, $(this).parents('.sideBlock')).fadeIn(800);
        }
    });


    /*Main Slider Invoking with pagers work...*/
    var mSlidPaths = new Array(), mSlideTitles = new Array(), mSlidalt = new Array(), indx = 0, mSlidTransition = '', hiddenPagers = new Array(), hiddenPagersHtml = '', nOItems = 0, scrollerFlipper = true;
    nOMainSliderItems = $('#main_slider .mainSliderListItem').length;
    /*Hide Arrows*/
    if (nOMainSliderItems <= 5) {
        $('.mainSliderThumbs_strip .next').addClass('superHide');
        $('.mainSliderThumbs_strip .prev').addClass('superHide');
    }

    hiddenPagersHtml = '<div class="hiddenPager">';
    for (i = 0; i < $('#main_slider .mainSliderListItem').length; i++) {
        hiddenPagers[i] = '.mainSliderThumbs_strip .hiddenPager .hPager-' + (i + 1);
        hiddenPagersHtml += '<a href="javascript:void(0);" class="hiddenPagerLink hPager-' + (i + 1) + '">' + (i + 1) + '</a>';
    }
    hiddenPagersHtml += '</div>';
    hiddenPagers.reverse();
    mSlidTransition = (isIe7()) ? 'h' : 'f';
    mSlidTransition = 'f';
    $('#main_slider .mainSliderListItem .mainSliderImageField img').each(function () { mSlidPaths[indx++] = $(this).attr('src'); mSlidalt[indx - 1] = $(this).attr('alt'); });
    indx = 0;
    $('#main_slider .mainSliderListItem .mainSliderTitleField').each(function () { mSlideTitles[indx++] = $(this).html(); });

    $('#main_slider').anythingSlider({
        theme: "default",
        mode: mSlidTransition,
        expand: false,
        resizeContents: false,
        showMultiple: false,
        easing: "easeInQuint",
        buildArrows: false,
        buildNavigation: true,
        buildStartStop: true,
        appendForwardTo: null,
        appendBackTo: null,
        appendControlsTo: null,
        appendNavigationTo: $(".mainSlider_block .mainSliderThumbs_strip .sliderThumbsCarousile"),
        appendStartStopTo: $(".mainSliderContent_container .playPauseButton"),
        toggleArrows: false,
        toggleControls: false,
        startText: "Start",
        stopText: "Stop",
        forwardText: "&raquo;",
        backText: "&laquo;",
        tooltipClass: "tooltip",
        enableArrows: true,
        enableNavigation: true,
        enableStartStop: true,
        enableKeyboard: true,
        startPanel: 1,
        changeBy: 1,
        hashTags: false,
        infiniteSlides: true,
        navigationFormatter: function (i, panel) { return '<a class="pagerThumbs" href="#"><img src="' + mSlidPaths[i - 1] + '" width="130" height="98" alt="' + mSlidalt[i - 1] + '" /><span class="selectedOverlayItem"></span></a><div class="thumbTitle">' + mSlideTitles[i - 1] + '</div>'; },
        navigationSize: false,
        autoPlay: true,
        autoPlayLocked: false,
        autoPlayDelayed: false,
        pauseOnHover: true,
        stopAtEnd: false,
        playRtl: false,
        delay: 3000,
        resumeDelay: 1000,
        animationTime: 300,
        delayBeforeAnimate: 0,
        onBeforeInitialize: function (e, slider) { },
        onInitialized: function (e, slider) {
            var topPager = $('.mainSliderThumbs_strip .thumbNav').clone(true);
            var nOPager = $('.mainSliderThumbs_strip .sliderThumbsCarousile ul li').length;
            var mSliderStartFrom = 0;
            if (isIe7()) {
                if (nOPager < 5) {
                    mSliderStartFrom = 0;
                } else {
                    mSliderStartFrom = nOPager - 5;
                }
            } else {
                mSliderStartFrom = nOPager - 5;
            }
            $('.pagerThumbs', topPager).remove();
            $('.mainSliderPager_container').append(topPager);
            if (nOMainSliderItems == 1) {
                var singleSliderPager = '<ul class="thumbNav"><li><a class="pagerThumbs" href="javascript:void(0);"><img src="' + mSlidPaths[0] + '" width="130" height="98" /><span class="selectedOverlayItem"></span></a><div class="thumbTitle">' + mSlideTitles[0] + '</div></li></ul>';
                $('.mainSliderThumbs_strip .sliderThumbsCarousile').html(singleSliderPager);
            } else {
                $('.mainSliderThumbs_strip').append(hiddenPagersHtml);
                var jcarousileObject = {
                    mouseWheel: false,
                    auto: false,
                    speed: 300,
                    easing: 'easeInQuint',
                    circular: false,
                    visible: 5,
                    start: mSliderStartFrom,
                    scroll: 1,
                    btnNext: "#Main_Slider_Next",
                    btnPrev: "#Main_Slider_Prev",
                    btnGo: hiddenPagers,
                    beforeStart: function (a) { },
                    afterEnd: function (a) { }
                };
                $('.mainSliderThumbs_strip .sliderThumbsCarousile').jCarouselLite(jcarousileObject);
            }
            $('.sliderThumbsCarousile .pagerThumbs:eq(0)').addClass('selectedThumb');
            $('.mainSlider_block .mainSliderTitle').append('<a href="javascript:void(0);" id="Top_PlayPaus_Button" title="ايقاف" class="playedButton"></a>');

            $('#Top_PlayPaus_Button').live('click', function () {
                if ($(this).hasClass('paused')) {
                    $('#main_slider').data('AnythingSlider').startStop(true);
                    $('#Top_PlayPaus_Button').attr('title', 'ايقاف');
                } else {
                    $('#main_slider').data('AnythingSlider').startStop(false);
                    $('#Top_PlayPaus_Button').attr('title', 'تشغيل');
                }
                $(this).toggleClass("paused");
            });

            var anythingObject = $('.mainSlider_block .anythingWindow'), mainSliderStripObject = $('.mainSlider_block .mainSliderBody .mainSliderThumbs_strip'), mainSliderObj = $('.mainSlider_block');

            mainSliderObj.delegate(mainSliderStripObject, "mouseenter", function () {
                if ($('#Top_PlayPaus_Button').hasClass('paused') != true) {
                    $('#main_slider').data('AnythingSlider').startStop(false);
                }
            });

            mainSliderObj.delegate(mainSliderStripObject, "mouseleave", function () {
                if ($('#Top_PlayPaus_Button').hasClass('paused') != true) {
                    $('#main_slider').data('AnythingSlider').startStop(true);
                }
            });

            /* Carousile Slider Hovering Effect*/
            var carSliderStrip = $('.mainSliderThumbs_strip');
            carSliderStrip.delegate(mainSliderStripObject, "mouseenter", function () {
                $(this).addClass('mainSliderCarousileHover');
            });

            carSliderStrip.delegate(mainSliderStripObject, "mouseleave", function () {
                $(this).removeClass('mainSliderCarousileHover');
            });

            /*$('.mainSliderThumbs_strip button.prev').bind('click', function () {
            scrollerFlipper = false;
            });

            $('.mainSliderThumbs_strip button.next').bind('click', function () {
            scrollerFlipper = false;
            });*/

        },
        onShowStart: function (e, slider) { },
        onShowStop: function (e, slider) { },
        onShowPause: function (e, slider) { },
        onShowUnpause: function (e, slider) { },
        onSlideInit: function (e, slider) { },
        onSlideBegin: function (e, slider) { },
        onSlideComplete: function (slider) {
            $('.thumbNav li a').removeClass('cur');
            $('.thumbNav li:eq(' + (slider.currentPage - 1) + ') a:not(.pagerThumbs)').addClass('cur');
            if (slider.currentPage <= 5) {
                $('.mainSliderThumbs_strip').find('.hPager-5').trigger('click');
            } else {
                $('.mainSliderThumbs_strip').find('.hPager-' + slider.currentPage).trigger('click');
            }
            $('.sliderThumbsCarousile .pagerThumbs').removeClass('selectedThumb');
            $('.sliderThumbsCarousile .pagerThumbs:eq(' + (slider.currentPage - 1) + ')').addClass('selectedThumb');
            $('.mainSlider_block .mainSliderTitle .sliderTitleText').fadeOut(100, 'swing', function () {
                $('.mainSlider_block .mainSliderTitle .sliderTitleText').html($('#main_slider .mainSliderListItem:eq(' + (slider.currentPage - 1) + ') .mainSliderSectionTitle').html());
            });
            $('.mainSlider_block .mainSliderTitle .sliderTitleText').fadeIn(200);
        },
        clickForwardArrow: "click",
        clickBackArrow: "click",
        clickControls: "click focusin",
        clickSlideshow: "click",
        allowRapidChange: false
    });

    if (isSafari()) {
        var pagerWidth = 0;
        $('.mainSliderPager_container .thumbNav li').each(function () {
            pagerWidth += parseInt($(this).outerWidth(true));
        });
        $('.mainSliderPager_container').width(pagerWidth);
    }

    /*Thumbnails Navigation...*/
    $('.mainSlider_block .mainSliderTitle .sliderTitleText').html($('#main_slider .mainSliderListItem:eq(0) .mainSliderSectionTitle').html());
    var thumbsClickedIndex = '';
    $('.sliderThumbsCarousile .pagerThumbs').live('click', function () {
        thumbsClickedIndex = $('.sliderThumbsCarousile .pagerThumbs').index(this);
        $('.sliderThumbsCarousile .pagerThumbs').removeClass('selectedThumb');
        $('.sliderThumbsCarousile .pagerThumbs:eq(' + thumbsClickedIndex + ')').addClass('selectedThumb');
    });

    jcarousileObject = {
        mouseWheel: false,
        auto: false,
        speed: 500,
        easing: 'easeInQuint',
        circular: false,
        visible: 4,
        start: $('.discussionsProgBlock .discProgCarousile ul li').length - 4,
        scroll: 4,
        btnNext: "#Discussion_Programs_prev",
        btnPrev: "#Discussion_Programs_next",
        beforeStart: function () { },
        afterEnd: function (a) { }
    };
    $('.discussionsProgBlock .discProgCarousile').jCarouselLite(jcarousileObject);

    /*Detecting Images inserted in html to generate the Pager HTML...*/
    var nofPagers = $('.photoAlbum_block .photoAlbumList .photoAlbumListItem').length;
    var paPagerClasses = new Array();
    var className = '';
    var activeClass = '';
    var pagerIndex = 0;
    var pagerHtml = new Array();
    var titlesArray = new Array(), arrayIndex = 0;
    for (i = 0; i < nofPagers; i++) {
        className = 'pager-' + (i + 1);
        var activeClass = '';
        if (i == 0) {
            activeClass = ' activePager';
        }
        pagerHtml[i] = '<a href="javascript:void(0);" class="paPagerItem ' + className + activeClass + '">' + i + '</a>';
        paPagerClasses[i] = '#photosPagerContainer .' + className;
    }

    /*$('#photosPagerContainer').html(pagerHtml.reverse());*/

    /*$('#photosPagerContainer').html(pagerHtml);*/

    pagerHtml = pagerHtml.reverse();

    $('#photosPagerContainer').html('');

    $.each(pagerHtml, function (idx, val) {
        $('#photosPagerContainer').append(val);
    });


    /*Generate Titles Array*/
    $('.photoAlbum_block .paSlidesContainer ul li').each(function () {
        titlesArray[arrayIndex++] = $(this).find('.photoAlbumTitle').html();
    });

    setPhotoAlbumTitle(titlesArray[0]);

    /*Invoke The JCarousile Lite plugin for photo album block...*/
    $(".photoAlbum_block .paSlidesContainer").jCarouselLite({
        mouseWheel: false,
        auto: false,
        speed: 500,
        easing: 'easeInQuint',
        circular: true,
        visible: 1,
        start: 0,
        scroll: 1,
        btnGo: paPagerClasses,
        btnNext: ".photoAlbum_block .photoAlbumSliderMainContainer .paPrevButton",
        btnPrev: ".photoAlbum_block .photoAlbumSliderMainContainer .paNextButton",
        beforeStart: function () {
            $('.photoAlbumList').fadeOut(300, 'easeInQuint');
        },
        afterEnd: function (e) {
            $('.photoAlbumList').fadeIn(200, 'easeInQuint');
        }
    });

    /*Pager Items Navigation process...*/
    /*indexClickedPager = $.inArray($('#photosPagerContainer .activePager'), $('#photosPagerContainer a'));*/
    $('#photosPagerContainer a').bind('click', function (event) {
        $('#photosPagerContainer a').removeClass('activePager');
        $(this).addClass('activePager');
        indexClickedPager = $.inArray(this, $('#photosPagerContainer a').get().reverse());
        setPhotoAlbumTitle(titlesArray[indexClickedPager]);
    });
    $('.photoAlbum_block .paNextButton').bind('click', function () {
        if (!(indexClickedPager < 1)) {
            indexClickedPager--;
            $('#photosPagerContainer a').removeClass('activePager');
            $('#photosPagerContainer a.pager-' + (indexClickedPager + 1)).addClass('activePager');
            setPhotoAlbumTitle(titlesArray[indexClickedPager]);
        } else {
            /*if not continuous don't trigger last pager item...*/
            indexClickedPager = nofPagers;
            $('#photosPagerContainer a.pager-' + (nofPagers)).trigger('click');
            setPhotoAlbumTitle(titlesArray[nofPagers - 1]);
        }
    });
    $('.photoAlbum_block .paPrevButton').bind('click', function () {
        if ((indexClickedPager < nofPagers - 1) && (indexClickedPager >= 0)) {
            indexClickedPager++;
            $('#photosPagerContainer a').removeClass('activePager');
            $('#photosPagerContainer a.pager-' + (indexClickedPager + 1)).addClass('activePager');
            setPhotoAlbumTitle(titlesArray[indexClickedPager]);
        } else {
            /*if not continuous don't trigger last pager item...*/
            indexClickedPager = 0;
            $('#photosPagerContainer a.pager-1').trigger('click');
            setPhotoAlbumTitle(titlesArray[indexClickedPager]);
        }
    });

    photoAlbumAutoSlider(1, nofPagers);

    $('.photoAlbum_block').hover(function () {
        photoAlbumHooverStatus = true;
    }, function () {
        photoAlbumHooverStatus = false;

        pASlider_ClearInterval();
        photoAlbumAutoSlider((indexClickedPager + 2), nofPagers);
    });
    /*End of photo album side block code...*/



    /********** Talks Shows *********/
    var URLTalkShows = "/ks3services/talkshowsportal";

    $.get(URLTalkShows, '', function (result, status, respones) {

        if (status == 'success') {

            if (result != "") {

                $('#TalkShowsDiv').html(result);
                /*Discussion Programs*/
                jcarousileObject = {
                    mouseWheel: false,
                    auto: false,
                    speed: 500,
                    easing: 'easeInQuint',
                    circular: false,
                    visible: 4,
                    start: $('.discussionsProgBlock .discProgCarousile ul li').length - 4,
                    scroll: 4,
                    btnNext: "#Discussion_Programs_prev",
                    btnPrev: "#Discussion_Programs_next",
                    beforeStart: function () { },
                    afterEnd: function (a) { }
                };
                $('.discussionsProgBlock .discProgCarousile').jCarouselLite(jcarousileObject);

                var indexOfSelectedArea = 0;
                $('.discProgCarousileWrapper .discussProgramsList .discussProgramsItem:not(.activeItem)').live('click', function () {
                    $('.discProgCarousileWrapper .discussProgramsList .discussProgramsItem').removeClass('activeItem');
                    $(this).addClass('activeItem');
                    indexOfSelectedArea = $.inArray(this, $('.discProgCarousileWrapper .discussProgramsList li').get());
                    $('.discussProgInfo').height('283px');
                    $('.disProgInfoList .disProgInfoItem').fadeOut('fast');
                    $('.disProgInfoList .disProgInfoItem').removeClass('shownItem');
                    $('.disProgInfoList .disProgInfoItem:eq(' + indexOfSelectedArea + ')').fadeIn(400, function () {
                        $('.discussProgInfo').height('auto');
                    });

                });
                $(".BriefTalkShowDesc").each(function () {
                    // debugger;
                    var OldDescription = $(this)[0].innerHTML;
                    var NewDescription = "";
                    var OldDescriptionArray = OldDescription.split(' ');
                    if (OldDescriptionArray.length > 3) {
                        for (var i = 0; i < 3; i++) {
                            NewDescription += OldDescriptionArray[i] + " ";
                        }
                        NewDescription += "...";
                    }
                    else {
                        NewDescription = OldDescription;
                    }

                    $(this)[0].innerHTML = NewDescription;

                });
            }

        }

    });

    /**********End Talks Shows *********/
    /********** Send to Friend Telegrams Portal *********/

    $('.send2FriendTelegramsPortal').live('click', function (ev) {

        if (document.getElementById("hidTelegramsSummary") != null) {
            document.getElementById("hidTelegramsSummary").value = $(this).parents('.telegraphListItem').children('#hidTelegramsSummary').attr('value');

        }
        var width = 560;
        var height = 330;
        var left = parseInt((screen.availWidth / 2) - (width / 2));
        var top = parseInt((screen.availHeight / 2) - (height / 2));
        var features = 'toolbar=no,status=no,resizable=no,menubar=no,scrollbars=no' + ',top=' + top + ',left=' + left + ',width=' + width + ',height=' + height;

        $("#isurgent").val("false");

        var winURL = '/Services/SendEmailTelegrams'; // Update Send to Friend Window
        //var winTitle = 'SendToFriend'; // No spaces allowed to work in ie8     
        //   var w = (window.open(winURL, winTitle, features)); //If used gonna show the opened win title
        var w = (window.open(winURL, '_blank', features));
        ev.preventDefault();



        return false;
    });
    /********** Send to Friend Telegrams Portal *********/

    /*Search Box Kepressing action*/
    $("#txtSearch").keypress(function (e) {

        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $('#btnSearch').click();
            return true;
        }
    });

    /*Latest News left side block news thumbs navigation, Transitions Work...*/
    var _title = $('.latestNews_block .latestNewsItem:eq(0) .hiddenTitle').html();
    var _summary = $('.latestNews_block .latestNewsItem:eq(0) .hiddenBody').text();
    var titleDiv = $('.latestNewsContent:eq(0) .latestNewsTitle');
    var summaryDiv = $('.latestNewsContent:eq(0) .latestNewsBrief');

    cropText(_title, _summary, 4, titleDiv, summaryDiv, 20, 19);

    var clickedThumbIndex = 0, selectedRowIndex = 1, parentItem = '', parentList = 0;

    $('.latestNewsContent:eq(0) .latestNewsTitle').html($('.latestNews_block .latestNewsItem:eq(0) .hiddenTitle').html());
    $('.latestNewsContent:eq(0) .latestNewsBrief').text($('.latestNews_block .latestNewsItem:eq(0) .hiddenBody').text());
    $('.latestNewsContent:eq(0)').removeClass('hiddenLatestNewsContent').addClass('shownLatestNewsContent').slideDown(500);
    $('#latestNewsTabContainer').hover(function () { lNewsPausedShow = true; }, function () { lNewsPausedShow = false; })
    var lastClickedIndex = 2;
    $('.latestNewsItem .latestNewsThumb a:not(.activeThumb)').live('click mouseover', function () {
        $('.latestNewsItem .latestNewsThumb a').removeClass('activeThumb');
        $(this).addClass('activeThumb');
        indexOfActiveNewsThum = $('.latestNewsItem .latestNewsThumb a').index($(this));
        parentItem = $(this).parents('.latestNewsItem');
        parentList = $(this).parents('.latestNewsList');
        clickedThumbIndex = parseInt($('.latestNewsItem', parentList).index(parentItem));
        selectedRowIndex = parseInt($('.latestNews_block .latestNewsList').index(parentList));
        $('.latestNewsContent:eq(' + selectedRowIndex + ') .latestNewsTitle').html($('.hiddenTitle', parentItem).html());
        $('.latestNewsContent:eq(' + selectedRowIndex + ') .latestNewsBrief').text($('.hiddenBody', parentItem).text());
        if (lastClickedIndex != selectedRowIndex) {
            lastClickedIndex = selectedRowIndex;
            $('.latestNewsContent:not(:eq(' + selectedRowIndex + '))').stop().slideUp(200, 'linear');
            $('.latestNewsContent:not(:eq(' + selectedRowIndex + '))').removeClass('shownLatestNewsContent').addClass('hiddenLatestNewsContent');
            $('.latestNewsContent:eq(' + selectedRowIndex + ')').removeClass('hiddenLatestNewsContent').addClass('shownLatestNewsContent').slideDown(400, 'linear');
        }
        _title = $('.hiddenTitle', parentItem).html();
        _summary = $('.hiddenBody', parentItem).text();
        titleDiv = $('.latestNewsContent:eq(' + selectedRowIndex + ') .latestNewsTitle');
        summaryDiv = $('.latestNewsContent:eq(' + selectedRowIndex + ') .latestNewsBrief');
        cropText(_title, _summary, 4, titleDiv, summaryDiv, 20, 19);

        moveLatestNewsArrow(clickedThumbIndex, selectedRowIndex);
    });


});    /*##########  End Document Ready State  ##########*/




